package com.interview.service.impl;

import com.interview.entity.Examee;
import com.interview.entity.SignedInfo;
import com.interview.entity.SignedStatics;
import com.interview.mapper.SignedInfoMapper;
import com.interview.mapper.SignedStaticsMapper;
import com.interview.service.ExameeService;
import com.interview.service.SignedInfoService;
import com.interview.utils.TimeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class SignedInfoServiceImpl implements SignedInfoService {

    @Autowired
    private SignedInfoMapper signedInfoMapper;
    @Autowired
    private ExameeService exameeService;
    @Autowired
    private SignedStaticsMapper signedStaticsMapper;

    @Override
    public boolean sign(String idNumber) {
        Examee examee = exameeService.getExameeById(idNumber);
        String name = examee.getName();
        String groupId = examee.getGroupId();
        SignedInfo signedInfo = new SignedInfo(idNumber,groupId,name, TimeUtils.getCurrentTime());
        int insert = signedInfoMapper.insert(signedInfo);

        if (insert == 1) {
            return true;
        }else {
            return false;
        }
    }

    @Override
    public List<SignedInfo> getAllSignedExamee() {
        List<SignedInfo> signedInfoList = signedInfoMapper.selectList(null);
        return signedInfoList;
    }

    @Override
    public SignedInfo getSignedExamee(String idNumber) {
        return signedInfoMapper.selectById(idNumber);
    }

    @Override
    public List<Map<String, String>> getSignedStatics() {
        return signedInfoMapper.getSignedStatics();
    }

    @Override
    public List<SignedStatics> getSignedStaticsList() {
        return signedStaticsMapper.selectList(null);
    }


}

